//Copyright (c) 2012 The cwkshell Authors. All rights reserved. 
// Use of this source code is governed by a BSD-style license that can be 
// found in the LICENSE file. 
#ifndef CUC_CWKSHELL_BROWSER_SHELL_BROWSER_H_ 
#define  CUC_CWKSHELL_BROWSER_SHELL_BROWSER_H_ 

#include <list>

#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_piece.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_contents_delegate.h"
#include "cuc/src/cwkshell/app/shell_property.h" 
#include "ipc/ipc_channel.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/native_widget_types.h"


class GURL;
namespace content {

	class BrowserContext;

	class SiteInstance;
	class WebContents;
}
namespace cuc{ 
	namespace shell{ 
		class ShellBrowserWindow;
		class ShellWindow;
		class ShellBrowserMainParts;
		class ShellBrowserContainer;
		class ShellBrowserDialog;
		class ShellBrowser  {
		public:
			explicit ShellBrowser(content::BrowserContext* browser_context);
			virtual ~ShellBrowser();		
			
			
			ShellWindow* CreateNewWindow(content::BrowserContext* browser_context,
				const GURL& url,
				content::SiteInstance* site_instance,
				int routing_id,
				const gfx::Size& initial_size);

			ShellWindow* CreateNewDialog(content::BrowserContext* browser_context,
				const GURL& url,
				content::SiteInstance* site_instance,
				int routing_id,
				const gfx::Size& initial_size);

			static ShellBrowser* instance(){return instance_;}

			static ShellProperty* property(){return instance()->GetShellProperty();}

			content::BrowserContext* GetBrowserContext()  {return browser_context_;}

			ShellBrowserContainer* GetShellBrowserContainer(){return shell_browser_container_.get();}

			ShellProperty* GetShellProperty(){return shell_property_.get();}

			void CloseWindow(const ShellWindow* window);

			int GetWindowCount(){return windows_.size();}


			void CloseAllWindows();

			void Quit();

			void OnWindowCreated(const ShellWindow* window);

		private:

		
			ShellBrowserContainer* CreateContanier(content::BrowserContext* browser_context,
				const GURL& url,
				content::SiteInstance* site_instance,
				int routing_id,
				content::WebContents* base_web_contents);

		
			friend class ShellWindow;
			friend class ShellBrowserMainParts;
			void PlatformInitialize();

			// Returns the ShellBrowserWindow object corresponding to the given content::RenderViewHost.


			// Returns the currently open windows.
			std::vector<const ShellWindow*>& windows() { return windows_; }


			// Closes all windows and exits.
			void PlatformExit();

			void PlatformCleanUp();

			content::BrowserContext* browser_context_;

			scoped_ptr<ShellBrowserContainer> shell_browser_container_;

			static ShellBrowser* instance_;

			scoped_ptr<ShellProperty> shell_property_;

			scoped_ptr<content::WebContents> first_web_content_;

			std::vector<const ShellWindow* > windows_;

			bool quit_message_loop_ ;

			DISALLOW_COPY_AND_ASSIGN(ShellBrowser);

		};

	} //namespace shell 
} //namespace cuc 
#endif //CUC_CWKSHELL_BROWSER_SHELL_BROWSER_H_ 
